import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-31
 * Time: 18:28
 */
class Solution26 {
    public int pileBox(int[][] box) {
        int n = box.length;
        //按照左端点排序
        Arrays.sort(box,(v1, v2)->{
            if(v1[0] != v2[0]) {
                return v1[0]-v2[0];
            }else {
                return v2[1]-v1[1];
            }
        });
        //1.dp[i]表示 以第i个下标结束最大套娃的个数
        int[] dp = new int[n];
        //2.初始化
        int ret = 0;
        for(int i = 0; i < n; i++) {
            int a = box[i][0],b = box[i][1],c = box[i][2];
            for(int j = 0; j <= i; j++) {
                if(box[j][0] < a && box[j][1] < b && box[j][2] < c) {
                    dp[i] = Math.max(dp[i],dp[j]+box[i][2]);
                }
            }
            //这个细节需要考虑！！！
            if(dp[i] == 0) {
                dp[i] = box[i][2];
            }
            ret = Math.max(dp[i],ret);
        }
        return ret;
    }
}
